def qishui(a):
    if a == 0:
        return
    if a < 2:
        return 0
    if a == 2 or a == 3:
        return 1
    else:
        n = a // 3
        b = (a % 3) + n
        return qishui(b) + n


if __name__ == '__main__':
    while True:
        a = int(input())
        if a == 0:
            break
        else:
            print(qishui(a))
